package test.core.fun;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import hyl.core.MyFun;
import hyl.core.fun.MyByte;
import hyl.core.safe.MyZip;

public class testbyte1 {
	public static void main(String[] arg) {

	}

	public void test() {
		byte[] 源 = { 2, 3, 4, 5, 12, 13, 14 };
		byte[] 目标 = { 6, 7, 8, 9, 10, 11 };
		byte[] c = { 16, 17, 8, 9 };
		byte[] d = { 26, 27, 8, 9 };
		int begin = 1;
		int end = 3;

		byte[] bt3 = MyFun.concat(源, 目标);

		MyByte.showbyte(bt3);
		// ByteBuffer bb;
		bt3 = MyFun.concat(源, 目标, c, d);
		MyByte.showbyte(bt3);

		MyFun.insert(源, 1, 3, 目标, 2);

		MyByte.showbyte(目标);

	}

	// @Test
	public void test1_0() {
		byte[] b1 = MyByte.binToBytes("1000010000010");
		byte[] b2 = MyByte.binToBytes("0100001000100");
		byte[] b3 = MyByte.orBits(b1, b2);
		System.out.println("-1-" + MyByte.bytesToBin(b3));

	}

	// @Test
	public void test1_1() {
		byte[] b1 = MyByte.binToBytes("1000010000010");
		byte[] b2 = MyByte.binToBytes("0100001000100");
		byte[] b3 = MyByte.binToBytes("001000010000100");
		byte[] b4 = MyByte.orBits(b1, b2, b3);
		System.out.println("-2-" + MyByte.bytesToBin(b4));

	}

	// @Test
	public void test1_2() {
		byte[] b1 = MyByte.binToBytes("1000010000010");
		byte[] b2 = MyByte.binToBytes("1100001000110");
		byte[] b3 = MyByte.xorBits(b1, b2);
		System.out.println("-3-" + MyByte.bytesToBin(b3));

	}

	// @Test
	public void test1_3() {
		byte[] b1 = MyByte.binToBytes("1000010000010001");
		byte[] b2 = MyByte.binToBytes("1100011000100001");
		byte[] b3 = MyByte.andBits(b1, b2);
		System.out.println("-4-" + MyByte.bytesToBin(b3));

	}

	// @Test
	public void test1_4() {
		byte[] b1 = MyByte.binToBytes("1000010000010001");
		byte[] b2 = MyByte.binToBytes("1100011000100001");
		byte[] b4 = MyByte.binToBytes("1101000000100000");
		byte[] b3 = MyByte.andBits(b1, b2, b4);
		System.out.println("-5-" + MyByte.bytesToBin(b3));

	}

	// @Test
	public void test2_1() {
		byte[] c = null;
		List<byte[]> bb = new ArrayList<>();

		bb.add(MyByte.binToBytes("1000010000010001"));
		bb.add(MyByte.binToBytes("1100011000100001"));
		bb.add(MyByte.binToBytes("1101000000100000"));
		for (byte[] m : bb) {
			c = MyByte.orBits(c, m);
			System.out.println(MyByte.countBit(c));
		}
		System.out.println(MyByte.bytesToBin(c));
		byte[] d = MyByte.ones(c.length);
		System.out.println(MyByte.bytesToBin(d));

		System.out.println(MyByte.bytesToBin(MyByte.xorBits(c, d)));

	}

	@Test
	public void test2_2() {
		byte[] b1 = "个爱上你的给看见啥到了关键看感觉你空间卡上的那个记得杀你公交".getBytes();
		System.out.println(b1.length);
		System.out.println(MyByte.bytesToHex(b1));
		byte[] b2 ,b3;
//		byte[] b2 = MyZip.do压缩1(b1);
//		System.out.println(MyByte.bytesToHex(b2));
//		byte[] b3 = MyZip.do解压1(b2);
//		System.out.println(MyByte.bytesToHex(b3));
		b2 = MyZip.do压缩(b1, 1);
		System.out.println(MyByte.bytesToHex(b2));
		b3 = MyZip.do解压(b2);
		System.out.println(MyByte.bytesToHex(b3));
		b2 = MyZip.do压缩2(b1, 1);
		System.out.println(MyByte.bytesToHex(b2));
		b3 = MyZip.do解压2(b2);
		System.out.println(MyByte.bytesToHex(b3));
		
		//测算压缩后数据与压缩前比较
		String s="158CDB0A404014007F1D2DB9E48D6423844412F1A0155F738EB3FB178ED76966480A3827F2373843B86B9282AE9C8A480F36A63DFA2B280FDDDD240BC357547A087E6D54263B306EB8E2C4382D4FF4B2E293BDA5C502BA33A8EE03";
		System.out.println(s.length()/2);	
//		b2 = MyZip.gZip(b1);
//		System.out.println(MyByte.bytesToHex(b2));
//		b3 = MyZip.unGZip(b2);
//		System.out.println(MyByte.bytesToHex(b3));
	}
	//@Test
	public void test2_3() {
		byte[] b1 =MyByte.zeros(90000000);
		byte[] b2 ,b3;
		b2 = MyZip.do压缩(b1, 2);
		System.out.println(MyByte.bytesToHex(b2));
		 b1 =MyByte.ones(90000);
		b2 = MyZip.do压缩2(b1, 1);
		System.out.println(MyByte.bytesToHex(b2));		
		String s="EDD0010D000000C2A0FEA96F0F0711280C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C183060C0800103060C1830F03930" ;
		System.out.println(s.length()/2);	
	}
	
	
}
